package java_14;


import java.io.*;

/*
获得文件行数的方法
 有 bufferedReader.readLine 方法 或者查找byte是否=='\n',比较谁快！
*/
public class Test_7 {
    public static void main(String[] args) {
        BufferedReader b = null;
        FileInputStream f=null;
        int count1=0;
        long start = System.nanoTime();
        {
            try {
                b = new BufferedReader(new FileReader("D:\\第一小组\\B.txt"));
                try {
                   while (b.readLine()!=null){
                      count1++;
                   }
                    long end=System.nanoTime();
                    System.out.println(count1);
                    System.out.println(end-start);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }finally {
                try {
                    b.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        int count =0;
         long start1=System.nanoTime();
        try {
            f=new FileInputStream("D:\\第一小组\\B.txt");
            byte[]bytes=new byte[f.available()];
           f.read(bytes);
           for (byte x:bytes){
               if (x==10){
                   count++;
               }
           }

            System.out.println(count);
            long end1=System.nanoTime();
            System.out.println(end1-start1);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                f.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}